// const baseUrl = 'http://192.168.0.105:8091/api';
const baseUrl = "https://www.cfxs.work/api"
import {mapMutations } from "vuex";
const httpRequest = (opts, data) => {
    let httpDefaultOpts = {
        url: baseUrl + opts.url,
        data: data,
        method: opts.method,
        header: opts.method == 'get' ? {
            'X-Requested-With': 'XMLHttpRequest',
            "Accept": "application/json",
            "Content-Type": "application/json; charset=UTF-8",
			"token":uni.getStorageSync("token"),
			"tokenKey":uni.getStorageSync("tokenKey")
        } : {                                                                                                
            'X-Requested-With': 'XMLHttpRequest',
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
			"token":uni.getStorageSync("token"),
			"tokenKey":uni.getStorageSync("tokenKey")
        },
        dataType: 'json',
    }
    uni.showLoading({
        title: "加载中"
    })
    let promise = new Promise(function (resolve, reject) {
        uni.request(httpDefaultOpts).then(
            (res) => {

				if(res[1].statusCode===404){
					uni.showModal({
						content:"登陆已过期",
						showCancel:false,
						success() {
							uni.navigateTo({url: '/pages/login/login'})
						}
					})
				}
                uni.hideLoading();
                resolve(res[1])
            }
        ).catch(
            (response) => {

                uni.hideLoading();
                reject(response)
            }
        )
    })
    return promise
};

export default {
    baseUrl,
    httpRequest
}